# install.packages("lpSolveAPI")
# install.packages("readstata13")
# install.packages("dplyr")

# Clear all
rm(list = ls()) 

#Load Packages
library(lpSolveAPI)
library(readstata13)
library(dplyr)

# Set Path <-- Direct to replication data folder
setwd("/Users/vedantvohra/Library/CloudStorage/Dropbox/ACR Bounds/Replication Kit")

# Load Function "cce"
source("Functions/cce.R")

# The function takes arguments (concavity_assumption, weights, acr).
# 1. concavity_assumption = 1 if beta_{m} > beta_{m+1}, 0 otherwise
# 2. weights is the vector type containing the appropriate weights
# 3. acr should be the appropriate value type containing the ACR
# Outputs Lower Bound, Upper Bound, and values of betas in both cases

# ACR by Weeks ------------------------------------------------------------

# Input observed weights as a vector
msg_weights <- read.dta13("Output/msg_w.dta") 
msg_weights <- as.vector(msg_weights[,2])


# Specify ACRs (absolute value)
hindi_acr <- 0.02976737
math_acr  <- 0.04487262

# LP Result assuming concavity
results_conc_hindi_weeks <- cce(1,msg_weights,hindi_acr)
results_conc_math_weeks <- cce(1,msg_weights,math_acr)

# Results -----------------------------------------------------------------

# Hindi (Bounds, assuming concavity)
results_conc_hindi_weeks$`Lower Bound`
results_conc_hindi_weeks$`Upper Bound`
# Verifying Proposition 2
hindi_acr/msg_weights[1]
hindi_acr*length(msg_weights)

# Math (Bounds, assuming concavity)
results_conc_math_weeks$`Lower Bound`
results_conc_math_weeks$`Upper Bound`

# Verifying Proposition 2
math_acr/msg_weights[1]
math_acr*length(msg_weights)
